﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Expressions.Compiler.Internal
{
    /// <summary>
    /// 
    /// </summary>
    internal sealed class Token<T>
    {
        /// <summary>
        /// 
        /// </summary>
        private readonly Entity<T> _entity;
        /// <summary>
        /// 
        /// </summary>
        private readonly bool _optional;

        internal Entity<T> Entity
        {
            get
            {
                return _entity;
            }
        }

        internal bool Optional
        {
            get
            {
                return _optional;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Token"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="optional">if set to <c>true</c> [optional].</param>
        public Token(Entity<T> token, bool optional = false)
        {
            _entity = token;
            _optional = optional;
        }


#if TRACE
        public override string ToString()
        {
            return _entity.ToString();
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns> 
        internal string Name
        {
            get
            {
                if (_optional)
                {
                    return string.Format("({0})", _entity.Name);
                }
                return _entity.Name;
            }
        }
#endif
    }

    /// <summary>
    /// 
    /// </summary>
    internal sealed class Token
    {
        /// <summary>
        /// 
        /// </summary>
        private readonly Entity _entity;
        /// <summary>
        /// 
        /// </summary>
        private readonly bool _optional;

        internal Entity Entity
        {
            get
            {
                return _entity;
            }
        }

        internal bool Optional
        {
            get
            {
                return _optional;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Token"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="optional">if set to <c>true</c> [optional].</param>
        public Token(Entity token, bool optional = false)
        {
            _entity = token;
            _optional = optional;
        }

#if TRACE
        public override string ToString()
        {
            return _entity.ToString();
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>

        internal string Name
        {
            get
            {
                if (_optional)
                {
                    return string.Format("({0})", _entity.Name);
                }
                return _entity.Name;
            }
        }
#endif
    }
}
